I have posted this question 2 times none worked I re scripted it and now I'm having more problems
Here's my code on the first page:
<?php
$host="XXXX"; // Host name
$username="XXXX"; // Mysql username
$password="XXXX"; // Mysql password
$db_name="XXXX"; // Database name
$tbl_name="XXXX"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// select record from mysql
$sql="SELECT * FROM $tbl_name order by id desc";
$result=mysql_query($sql);
?>
<table background='images/view.png' width='50%'>
<tr>
<th align='center'>Post #</th><th align='center'>Submition By</th><th align='center'>ScreenName</th><th align='center'>Password</th><th align='center'>Does This Work?</th><th align='center'>Vote</th>
</tr>
<tr>
<th align='center'>
<hr color='lime' width='100%'/>
</th>
<th align='center'>
<hr color='lime' width='100%'/>
</th>
<th align='center'>
<hr color='lime' width='100%'/>
</th>
<th align='center'>
<hr color='lime' width='100%'/>
</th>
<th align='center'>
<hr color='gold' width='100%'/>
</th>
<th align='center'>
<hr color='gold' width='100%'/>
</th>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td background='transparent' align='center'><i><b><? echo $rows['id']; ?> </b></i></td>
<td background='transparent' align='center'><i><b><? echo $rows['yname']; ?> </b></i> </td>
<td background='transparent' align='center'><i><b><? echo $rows['username']; ?></b></i></td>
<td background='transparent' align='center'><i><b><? echo $rows['password']; ?></b></i></td>
<td background='transparent' align='center'><i><b><? echo $rows['works']; ?>% Yes <font color='transparent'>||||</font> <? echo $rows['dworks']; ?>% No</b></i>
<td background='transpatent' align='center'><i><b><a href='works.php?id=<? echo $rows['id']; ?>'><img src='images/ThumbsUp.png' height='30' width='30'> </a> <a href='dworks.php?id=<? echo $rows['id']; ?>'><img src='images/ThumbsDown.png' height='30' width='30'></a>
</td>
</tr>
<?php
// close while loop
}
?>
<?php
// close connection;
mysql_close();
?>
</table>
im not sure if this page is part of the problem yet...
here is the second page
<?php
$host="XXXX"; // Host name
$username="XXXX"; // Mysql username
$password="XXXX"; // Mysql password
$db_name="XXXX"; // Database name
$tbl_name="XXXX"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// get value of id that sent from address bar
$id=$_GET['id'];
// Retrieve data from database
$sql="SELECT * FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>
<?php
$host="XXXX"; // Host name
$username="XXXX"; // Mysql username
$password="XXXX"; // Mysql password
$db_name="XXXX"; // Database name
$tbl_name="XXXX"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// update data in mysql database
$sql="UPDATE `$host`.`$username`
SET `works` = `works` + 1 WHERE `$db_name`.`id` = '".$id."'";
$result=mysql_query($sql);
// if successfully updated.
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='list_records.php'>View result</a>";
}
else {
echo "ERROR";
}
?>
I'm getting the error on my custom error page and I don't know why .. I'm trying to make it add +1 to a column on my table named works the default value is 0 and i cant get it to add +1 say the value is 1 and someone clicks the image link the value changes to 2 and another click it goes to 3 so on and so forth
Yes this is real mysql login information this is not my perm site its just to test my code to put on my real site so I don't care sharing that
Change following
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
to
$link=mysql_connect($host, $username, $password);
if (!$link) {
die('Not connected : ' . mysql_error());
}
$db_selected=mysql_select_db("$db_name", $link);
if (!$db_selected) {
die('Not selected : ' . mysql_error());
}
To fetch data and print
$sql="SELECT * FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);
if(mysql_num_rows($result))
{
while($row = $result->fetch_assoc()) {
echo 'id: '. $row['id'].'<br />'; // replace with real field name
echo 'name: '. $row['name']'<br />'; // replace with real field name
}
}
changed last query to $sql="UPDATE tylted SET works = works + 1 WHERE id = $id;"; $result=mysql_query($sql); and it works i google searched for 9 or 10 min and found MySQL Update Column +1? i searched for this here also and it didnt work thanks people for helping as much as u did