Jump to content

darkenroyce

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

darkenroyce's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi Guys I'm running a update query which is supposed to enter some data for me via a drop dialogue box from a web page with a form. The code is as follows: $sql="SELECT id FROM squad ORDER BY id DESC LIMIT 1"; $f=mysql_query($sql, $con) or die(mysql_error()); $a = mysql_fetch_assoc($f); $row = $a++; $sql_s="UPDATE squad SET play = '$_POST[sub]' WHERE us='$id' AND id='$row'"; mysql_query($sql_s, $con) or die(mysql_error()); The code for the drop down dialogue box is as follows: <select name="sub"> <?php $con = mysql_connect("localhost", "root") or die(mysql_error()); mysql_select_db("dbase", $con) or die(mysql_error()); $s = "SELECT id, name, value, position FROM players WHERE position='Q'"; $q = mysql_query($s, $con); while($queryCol= mysql_fetch_array($q)){ echo '<option value="' . $queryCol ['id'] . '">' . $queryCol ['id'] . ' ' . $queryCol ['name'] . ' - ' . $queryCol ['player'] .'</option>'; } ?></select> The drop dialogue box passes option value id to the update query which needs to populate where us=$id (the row's id & primary key) and to the next blank row after the previous row has been filled in the table hence $a++. It does not since MySQL table displays 0 when the id should be there. Is it because the fetch is incorrect? It is a two part registration system that requires the user id to ensure that the new user can register their details and then they choose players from the drop down box to place in the squad they intend to submit. Please advise. If this is unclear, I can provide you with my msn address via a private message. Cheers, Darkenroyce
  2. Hi Guys I'm getting the syntax problem with the following code: $sql="INSERT INTO squad (players) VALUES ('$_POST[playerid]') WHERE p_id="$id""; mysql_query($sql, $con) or die(mysql_error()); p_id is the player ID within the SQL table, and $id - $id = $_GET ['n_id']; - is a integer php variable passed through a URL. Tried to googling this but found no simple syntax correction. Please advise.... Cheers Darkenroyce
  3. Hi I want to use an input from a drop dialogue box which displays a list of user records from a column of in a MySQL table. When the users select the option they wish to delete they need to press the "submit button" labelled 'delete'. I have coded the drop down dialogue box but I can't the button to delete the record within the MySQL table. The code for the drop dialogue box is below: <td><select> <?php $conn = mysql_connect("localhost", "root") or die(mysql_error()); //database selected mysql_select_db("database", $conn) or die(mysql_error()); $state = "SELECT name FROM data"; $query = mysql_query($state, $conn); while($queryColumn = mysql_fetch_array($query)){ echo '<option value="' . $queryColumn ['name'] . '">' . $queryColumn ['name'] . '</option>'; } ?> I using the <form action = "filename" METHOD=POST></form> for this small form. The php file this redirects to runs this php code: <?php $con = mysql_connect("localhost","root") or die(mysql_error()); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database", $con); $sql3 = "DELETE FROM data WHERE name VALUES ('$_POST[delete_data]')" mysql_query($sql3,$con); mysql_close($con); ?> delete_data refers to <input type="submit" name="delete_data" value="Delete"> Am I along the right tracks or completed wrong. This has been racking my brain for a while... Thanks
  4. Hi Guys I am creating a sports database and one of the features involves create drop down dialogue boxes that retrieve data from MySQL tables and provides them as <option> within <select></select>. I am using PHP for this and I'm fairly new at the programming language. I have got the dialogue to work with respect to retrieving the data from MySQL table but it only displays the data from first row/first column of the table twice. I want the foreach loop to iterate down the rows of the first column until it reaches the end of these rows in the MySQL table. Below is the code I used to do it. Please help me to find where I went wrong: <td><select> <?php $conn = mysql_connect("localhost", "root") or die(mysql_error()); //database selected mysql_select_db("database", $conn) or die(mysql_error()); $state = "SELECT player_name FROM table1"; $query = mysql_query($state, $conn); $queryColumn = mysql_fetch_array($query); $aData = $queryColumn; foreach( $aData as $test ){ echo '<option value="' . $aData . '">' . $test . '</option>'; } ?> </select></td> Thanks for your help much appreciated! I've been stuck on this for a while now.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.