Jump to content

mysql php


anf.etienne

Recommended Posts

I have a php form with that has four radio buttons. Depending on which radio button is submitted i want php to get information from my db.

 

the ID of the buttons are 1,2,3 and 4.....they correspond to row 1,2,3 and 4 of my db how do i retieve rows 1 if button 1 is selected? Ive been through a lot of websites to find out but they dont explain retrieving a specific row

Link to comment
https://forums.phpfreaks.com/topic/144209-mysql-php/
Share on other sites

At the end of your query, add:

 

LIMIT X, 1

 

Change X to the number of the database row you want. How this works is that it starts at row X, and gives you 1 row. And remember, X will start at 0, so if you want the first row, you will set X=0, and if you want the second row, you will set X=1 etc.

Link to comment
https://forums.phpfreaks.com/topic/144209-mysql-php/#findComment-757147
Share on other sites

no i don't want to create anything as complicated as that yet. I just want to create a php form where a user selects either options 1, 2, 3 or 4 and when they click continue the php will retrieve the either row with the corresponding ID.

 

I've not done php & mysql for a loooong time and went more into graphic design and ive forgotten a lot of things lol so now im back to being a php swl newbie......the joy.

 

thanks in advance for anyone that recaps me on this lol

Link to comment
https://forums.phpfreaks.com/topic/144209-mysql-php/#findComment-757671
Share on other sites

hi! try this...Hope its work for you.

 

<?php

define("HOST", "localhost");

// Database user

define("DBUSER", "root");

// Database password

define("PASS", "******");

// Database name

define("DB", "Database_Name"); //Database_Name

############## Make the mysql connection ###########

$conn = mysql_connect(HOST, DBUSER, PASS);

if (!$conn){

// the connection failed so quit the script

die('Could not connect !<br />Please contact the site\'s administrator.');

}

$db = mysql_select_db(DB);

if (!$db){

// cannot connect to the database so quit the script

die('Could not connect to database !<br />Please contact the site\'s administrator.');

}

?>

<form id="form1" name="form1" method="post" action="test.php">

<p>

  <label>

    <input type="radio" name="radio1" id="r1" value="1" <?=($_POST['radio1'])==1?'checked':''?> />1</label>

  <label>

    <input type="radio" name="radio1" id="r2" value="2" <?=($_POST['radio1'])==2?'checked':''?> />2</label>

  <label>

    <input type="radio" name="radio1" id="r3" value="3" <?=($_POST['radio1'])==3?'checked':''?> />3</label>

  <label>

    <input type="radio" name="radio1" id="r4" value="4" <?=($_POST['radio1'])==4?'checked':''?> />4</label>

  </p>

<p>

    <input type="submit" value="Get Row" />

    </p>

</form>

<?

if($_POST){

$sql = "select user_id,name,email from sys_user where user_id='".$_POST['radio1']."';";

$res = mysql_query($sql);

    while ($row = mysql_fetch_array($res)){

echo $row[0].' - '.$row[1].' - '.$row[2]."<br>";

}

mysql_free_result($res);

mysql_close();

}

?>

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/144209-mysql-php/#findComment-757967
Share on other sites

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.